package com.study.bindview_compiler;

import com.study.bindviewannotation.BindView;

import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Name;
import javax.lang.model.type.TypeMirror;

/**
 * 作者： zjf 10/15/20 5:15 PM
 * 描述：
 */
public class BindViewField {

    private int id;
    private Element element;

    public BindViewField(Element element) {
        //做一些健壮性判断
        if (element.getKind() != ElementKind.FIELD) {
            throw new RuntimeException(BindView.class.getName() + ":必须作用于元素上");
        }
        this.element = element;
        BindView bindView = element.getAnnotation(BindView.class);
        id = bindView.value();
        if (id < 0) {
            throw new RuntimeException("资源ID怎么可能是负数呢");
        }
    }

    public int getResId() {
        return id;
    }

    public Name getFieldName() {
        return element.getSimpleName();
    }

    public TypeMirror getFieldType() {
        return element.asType();
    }
}
